package com.neusoft.controller;

import com.neusoft.domain.Food;
import com.neusoft.domain.Result;
import com.neusoft.domain.ResultPage;
import com.neusoft.domain.vo.FoodVo;
import com.neusoft.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/foods")
public class FoodController {

    @Autowired
    private FoodService foodService;

    @GetMapping("/findFoodByPage")
    public Result<ResultPage<FoodVo>> findFoodByPage(Integer page,Integer pageSize,String foodName,Integer businessId){
        // 1. 接收参数
        // 2.调用service层完成业务逻辑处理
        ResultPage<FoodVo> resultPage =foodService.findFoodByPage(page,pageSize,foodName,businessId);
        // 3.响应数据给前端
        return Result.success(resultPage);
    }

    @PostMapping("/saveFood")
    public Result saveFood(@RequestBody Food food){
        // 1. 接收参数
        // 2.调用service层完成业务逻辑处理
        foodService.saveFood(food);
        // 3.响应数据给前端
        return Result.success();
    }

    @PutMapping("/updateFood")
    public Result updateFood(@RequestBody Food food){
        // 1. 接收参数
        // 2.调用service层完成业务逻辑处理
        foodService.updateFood(food);
        // 3.响应数据给前端
        return Result.success();
    }
}
